
//封装toast框框
//传入对象为参数，设置默认值
export const toast = ({title='正在加载中',duration=1000,icon="none",mask=true}={})=>{
  wx.showToast({
    title,
    duration,
    icon,
    mask,
    success: (res) => {},
    fail: (res) => {},
    complete: (res) => {},
  })
}

//封装模态框

const modal = (options)=>{
  return new Promise((resolve)=>{

    //设置默认的配置项和用户传入的配置项
    //设置默认配置项
    const defaultOpt = {
      title: '提示',
      content: '您确认执行该操作吗？'
    }
    //设置用户配置项与默认配置合并
    const totalOpt = Object.assign({},defaultOpt,options)


    wx.showModal({
      ...totalOpt,
      complete: ({cancel,confirm}) => {
        if (cancel) {
          resolve(false)
        }
        if (confirm) {
          resolve(true)
        }
      }
    })
  })
}


//将方法挂载到全局
wx.toast = toast
wx.modal = modal

